$(document).ready(function($){
    
    hideSidelinks();
    
    $(window).resize(function() {
        hideSidelinks();
    });
    
    $('#top-section').hide();
    
    // give main menu its functionality
    // see http://www.prowebdesign.ro/how-to-deal-with-hover-on-touch-screen-devices/ for touchscreen support
    
    if (!("ontouchstart" in document.documentElement)) {
        document.documentElement.className += " no-touch";
    }
    
    if (!$('html').hasClass('no-touch')) { //Execute code only on a touch screen device   
        $('li.main-menu > a:not(".no-submenu")').click(function(event) {
            $(this).parent().parent().find('li.sub-menu').hide(); // hide all submenus
            var submenuItems = $(this).parent().find('li.sub-menu');
            $(submenuItems).show();
            if ($(submenuItems).first().css('display') !== 'block') { // submenu not visible at this point
                $(submenuItems).show(); // make items visible
            }
            event.stopPropagation();
            event.preventDefault();
        });        
    }
    
//    $('#nav li.sub-menu').click(function() {
//        window.location.replace($(this).find('a').first().attr('href'));
//    });


    $(document).mousemove(function(event) {
        if (event.pageY <= 20 && $('#top-section').css('display') != 'block') {
            $('#top-section').fadeIn();
        } else {
            if (event.pageY >= 20 && $('#top-section').css('display') == 'block') {
                $('#top-section').fadeOut();
            }
        }
    });
});

function hideSidelinks() {
    if ($('#bodyContent').width() < 1060) {
        $('#modal').hide();
    } else {
        $('#modal').show();
    }
}